<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<!-- 添加的服务名称 -->
		<form class="form-horizontal m" id="form-service-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">服务名称：</label>
				<div class="col-sm-8">
					<input id="serviceName" name="serviceName" class="form-control"
						type="text">
				</div>
			</div>

			<!-- 添加的服务的价格 -->
			<div class="form-group">
				<label class="col-sm-3 control-label">服务价格：</label>
				<div class="col-sm-8">
					<input id="servicePrice" name="servicePrice" class="form-control"
						type="text">
				</div>
			</div>

			<!-- 添加的服务类型 -->
			<div class="form-group">
				<label class="col-sm-3 control-label">服务类型：</label>
				<div class="col-sm-8">
					<select id="getTosName" name="tosId" class="dropdown-header"></select>
				</div>
			</div>

		
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript">
		
	$("#form-service-add").validate({
		rules:{
			serviceName:{
				required:true,
			},
	servicePrice:{
		required:true,
		checkMoney:true
	}}
	});
	$.validator.addMethod("checkMoney",function(value,element,params){  
        var checkMoney = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;  
        return this.optional(element)||(checkMoney.test(value));  
    },"请输入正确的金钱格式");
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save( "/service/add", $('#form-service-add').serialize());
	        }
	    }
         //展示服务类型名称
		 tosName();
         function tosName(){
         	$.ajax({
                 type: "post",
                 url: "/service/selectTosName",
                 dataType: "json",
                 success: function(res){
                     if (null != res) {
                        var html= '';
                         Object.keys(res).forEach(function(key){
                             html += '<option value="' + res[key].tosId + '" label="'+ res[key].tosName+'"></option>';
                         });
                         $('#getTosName').html(html);
						 $('#getTosName').addClass("form-control");

                     }}
              });
            
         	 
         }
	</script>
</body>
</html>
